package cn.turing.ssm.controller;

import cn.turing.ssm.entity.UserInfo;
import cn.turing.ssm.mapper.UserInfoMapper;
import cn.turing.ssm.service.UserInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName HelloController
 * @Description: TODO
 * @Author gmllt20171110
 * @Date 2020/1/24
 * @Version V1.0
 **/
@Controller
public class HelloController
{
    @Resource
    private UserInfoMapper userInfoMapper;

    @Resource
    private UserInfoService userInfoService;

    @GetMapping("/hello")
    @ResponseBody
    public String hello()
    {
        return "hello world!";
    }

    @GetMapping("/freemark")
    public ModelAndView freemark()
    {
        ModelAndView mv=new ModelAndView("hello");

        UserInfo userInfo=userInfoMapper.findById(3);

        mv.addObject("user",userInfo);
        mv.addObject("hello","world");

//        Map param=new HashMap();
//        param.put("username","admin");
//        param.put("phone","139");
        List<UserInfo> users=userInfoMapper.findAll("admin","139");

        for(UserInfo u:users)
        {
            System.out.println(u.getUsername()+":"+u.getPhone());
        }
        return mv;
    }

    @GetMapping("/init")
    @ResponseBody
    public String init()
    {
        userInfoService.initUserInfo();
        return "SUCCESS";
    }
}
